# ===============================
# Stage 1: Build Vue App
# ===============================
FROM node:20-bullseye as build-stage

WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps
COPY . .

# 给 node_modules/.bin 下的命令加执行权限
RUN chmod -R +x ./node_modules/.bin

# 使用 npx 构建
RUN npx vite build

# ===============================
# Stage 2: Nginx Production
# ===============================
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build-stage /app/dist /usr/share/nginx/html

# 复制自定义Nginx配置（核心：添加SPA fallback）
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]